/*
 * @Author: mikey.zhaopeng
 * @Date:   2016-01-14 16:10:52
 * @Last Modified by:   mikey.zhaopeng
 * @Last Modified time: 2016-07-13 16:54:36
 */

'use strict';
/**
 * [工具栏区域]
 */
define([
    '../base/baseView',
    '../model/video',
], function(
    BaseView,
    videoModel
) {
    function Tools() {
        BaseView.apply(this, arguments);
        var self = this;
        this.init = function() {
            self.$el = $('#video-container');
            self.render();
            self.event();
        }

        this.render = function() {
            var self = this;
            videoModel.queryApps(function(apps) {
                var $app = self.$el.find('select[name="app-select"]');
                var $owner = self.$el.find('select[name="owner-select"]');
                self._.each(apps, function(app) {
                    var optionHtml = '<option value="' + app.name + '"> ' + app.name + ' </option>';
                    $app.append(optionHtml);
                });
                $app.select2();
                $owner.select2({
                    minimumResultsForSearch: Infinity
                });
            });
        }

        this.event = function() {
            self.$el.off('click', '.btn-search').on('click', '.btn-search', $.proxy(self.search, self));
            self.$el.off('click', '.btn-upload').on('click', '.btn-upload', $.proxy(self.upload, self));
        }

        /**
         * 点击查询按钮
         */
        this.search = function(e) {
            var params = { cPage: 1 };
            params.isMy = self.$el.find('select[name="owner-select"]').val();
            var appNames = self.$el.find('select[name="app-select"]').val();
            if (appNames.length > 0) {
                params.appNames = [appNames];
            } else {
                delete params.appNames;
            }
            self.$el.trigger('queryVideo', params);
        }

        this.upload = function(event) {
            var params = {};
            self.$el.trigger('uploadVideo', params);
        }


    };
    return new Tools();
});
